#include "RunParams.h"

#include <qmutex>
#include <QMutexLocker>
#include <qapplication>

#include <QApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QFile>

RunParams* RunParams::paramsInstance_ = nullptr;
QMutex mtxRunParams_;

RunParams* RunParams::instance()
{
    if (paramsInstance_ == nullptr)
    {
        QMutexLocker<QMutex> mtxLocker(&mtxRunParams_);
        paramsInstance_ = new RunParams();
    }

    return paramsInstance_;
}

void RunParams::destroy()
{
    delete paramsInstance_;
    paramsInstance_ = nullptr;
}

void RunParams::loadAllParams()
{

}


//void RunParams::loadProductParams()
//{
//    QJsonDocument readAlg;
//    QString strPath = QCoreApplication::applicationDirPath() + "/config/databaseCfg.json";
//    QFile file(strPath);
//    QByteArray jsonData;
//    if (file.open(QIODevice::ReadOnly)) {
//        jsonData = file.readAll().trimmed();
//        file.close();
//    }
//    QJsonParseError err_rpt;
//    QJsonDocument jsonDocu = QJsonDocument::fromJson(jsonData, &err_rpt);
//    if (jsonDocu.isObject())
//    {
//        // 读取ui交互参数，保存到数据库内容
//        auto uiInfos = jsonDocu["ui_editInfos"];
//        motorParams_.curProductSpec = uiInfos["diameterSpec"].toDouble();
//    }
//}
